package com.hspedu.newData.dmsxl.数组;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-10 
 * @Version: 1.0
 */

public class LC2918数组的最小相等和 {

    public long minSum(int[] nums1, int[] nums2) {

        int count1 = 0;
        int count2 = 0;

        long sum1 = 0;
        long sum2 = 0;

        for (int i = 0; i < nums1.length; i++) {
            sum1 += nums1[i];
            if (nums1[i] == 0){
                count1++;
            }
        }

        for (int i = 0; i < nums2.length; i++) {
            sum2 += nums2[i];
            if (nums2[i] == 0){
                count2++;
            }
        }

        if (count1 == 0 && count2 == 0){
            return sum1 == sum2 ? sum1 : -1;
        } else if (count1 == 0) {
            if (sum1 >= sum2+count2){
                return sum1;
            }else {
                return -1;
            }
        } else if (count2 == 0) {
            if (sum2 >= sum1+count1){
                return sum2;
            }else {
                return -1;
            }
        }

        long l = sum1 + count1;
        long x = sum2 + count2;

        return l>x?l:x;
    }


    @Test
    public void test() {
        // 测试代码

        long l = minSum(new int[]{8,13,15,18,0,18,0,0,5,20,12,27,3,14,22,0}, new int[]{29,1,6,0,10,24,27,17,14,13,2,19,2,11});
        long l1 = minSum(new int[]{2, 0, 2, 0}, new int[]{1, 4});
        System.out.println("------");

    }
}
